package com.ewzj.bigdata.mvp.ui.adapter

import android.app.Activity
import android.view.View

import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.mvp.model.bean.CitygroupBean
import com.ewzj.bigdata.mvp.model.rspbean.CityBean
import com.jess.arms.base.BaseApplication
import com.jess.arms.utils.DataHelper

/**
 * author:zhangjing
 * 作用:
 * return:
 */

class CityAdapter(data: List<CitygroupBean>) : BaseSectionQuickAdapter<CitygroupBean, BaseViewHolder>(R.layout.item_city, R.layout.item_section, data) {

    override fun convertHead(baseViewHolder: BaseViewHolder, citygroupBean: CitygroupBean) {
        baseViewHolder.setText(R.id.tv_index, citygroupBean.header)
    }

    override fun convert(baseViewHolder: BaseViewHolder, citygroupBean: CitygroupBean) {
        baseViewHolder.setText(R.id.tv_cityname, citygroupBean.t.city)
        if (!citygroupBean.isHeader) {
            baseViewHolder.getConvertView().setOnClickListener { kotlin.run{
                var gson=(mContext.applicationContext as BaseApplication).appComponent.gson()
                DataHelper.SetStringSF(mContext,AppKey.LOCATION_CITY,gson.toJson(citygroupBean.t))
                (mContext as Activity).finish()
            } }
        }

    }
}
